home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 June: Reference Library / Dev.CD Jun 96 RL / Dev.CD Jun 96 RL.toast / What's New? / Development Kits / Apple Game Sprockets DR1 / Headers / InputSprocket.h < prev    next >
Encoding:
Text File  |  1996-04-24  |  14.7 KB  |  631 lines  |  [TEXT/MPS ]

  1. //
  2. // InputSprocket.h  0.2
  3. // 3/14/96
  4. //
  5.  
  6. #ifndef __InputSprocket__
  7. #define __InputSprocket__
  8.  
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12.  
  13. // ********************* data types *********************
  14. #include <DriverServices.h>
  15.  
  16. #ifndef opaque
  17. #define opaque void *
  18. #endif
  19.  
  20. typedef struct opaqueDeviceData *DeviceReference;
  21. typedef struct opaqueElementData *ElementReference;
  22. typedef struct opaqueElementListData *ElementListReference;
  23. typedef OSType ElementLabel;
  24. typedef OSType ElementKind;
  25.  
  26. /*
  27.  * DeviceDefinition
  28.  *
  29.  * This structure provides all the available
  30.  * information for an input device within the system
  31.  *
  32.  */
  33.  
  34. typedef struct
  35. {
  36.     OSType deviceType;            // every distinguishable device should have an OSType
  37.     UInt32 permanentId;            // a cross reboot id unique within that deviceType, 0 if not possible
  38. } DeviceDefinition;
  39.  
  40. /*
  41.  * ElementEvent, ElementEventPtr
  42.  *
  43.  * This is the structure that event data is passed in.
  44.  *
  45.  */
  46.  
  47. typedef struct
  48. {
  49.     AbsoluteTime when;                  // this is absolute time on PCI or later, otherwise it is
  50.                                         // 0 for the hi 32 bits and TickCount for the low 32 bits
  51.     ElementReference element;            // a reference to the element that generated this event
  52.     UInt32 refCon;                        // for application usage, 0 on the global list
  53.     SInt32 data;                        // the data for this event
  54. } ElementEvent, *ElementEventPtr;
  55.  
  56. /*
  57.  * ElementInfo, ElementInfoPtr
  58.  *
  59.  * This is the generic definition of an element.
  60.  * Every element must contain this information.
  61.  *
  62.  */
  63. typedef struct ElementInfo
  64. {
  65.     ElementLabel theLabel;
  66.     ElementKind theKind;
  67.     Str63 theString;
  68. } ElementInfo, *ElementInfoPtr;
  69.  
  70. /*
  71.  * These are the current built in ElementKind's
  72.  * 
  73.  * These are all OSTypes.
  74.  *
  75.  */
  76.  
  77. enum
  78. {
  79.     kElementKindTrigger = 'trig',
  80.     kElementKindButton = 'butn',
  81.     kElementKindDPad = 'dpad',
  82.     kElementKindAxis = 'axis' 
  83. };
  84.  
  85.  
  86. /*
  87.  *
  88.  * These are the current built in ElementLabel's
  89.  *
  90.  * These are all OSTypes.
  91.  *
  92.  */
  93.  
  94. enum
  95. {
  96.     // axis
  97.     kElementLabelXAxis = 'xaxi',
  98.     kElementLabelYAxis = 'yaxi',
  99.     kElementLabelZAxis = 'zaxi',
  100.     
  101.     kElementLabelRx = 'rxax',
  102.     kElementLabelRy = 'ryax',
  103.     kElementLabelRz = 'rzax',
  104.     
  105.     kElementLabelGas = 'gasp',
  106.     kElementLabelBrake = 'brak',
  107.     kElementLabelClutch = 'cltc',
  108.     
  109.     kElementLabelThrottle = 'thrt',
  110.     kElementLabelTrim = 'trim',
  111.     
  112.     // direction pad
  113.     kElementLabelPOVHat = 'povh',
  114.     kElementLabelPadMove = 'move',
  115.     
  116.     // buttons
  117.     kElementLabelFire = 'fire',
  118.     kElementLabelStart = 'strt',
  119.     kElementLabelSelect = 'optn'
  120. };
  121.  
  122. /*
  123.  *
  124.  * direction pad data & configuration information
  125.  *
  126.  */
  127.  
  128. typedef enum
  129. {
  130.     kPadIdle = 0,
  131.     kPadLeft,
  132.     kPadUpLeft,
  133.     kPadUp,
  134.     kPadUpRight,
  135.     kPadRight,
  136.     kPadDownRight,
  137.     kPadDown,
  138.     kPadDownLeft
  139. } DPadData;
  140.  
  141. typedef struct
  142. {
  143.     UInt32 id;                // ordering 1..n, 0 = no relavent ordering of direction pads
  144.     Boolean fourWayPad;        // true if this pad can only produce idle + four directions
  145. } DPadConfigurationInfo;
  146.  
  147. /*
  148.  *
  149.  * button data & configuration information
  150.  *
  151.  */
  152.  
  153. typedef enum
  154. {
  155.     kButtonUp = 0,
  156.     kButtonDown = 1
  157. } ButtonData;
  158.  
  159. typedef struct
  160. {
  161.     UInt32 id;                // ordering 1..n, 0 = no relavent ordering of buttons / triggers
  162. } ButtonConfigurationInfo;
  163.  
  164. /*
  165.  *
  166.  * trigger data & configuration information
  167.  *
  168.  */
  169.  
  170. typedef enum
  171. {
  172.     kTriggerActivated = 1
  173. } TriggerData;
  174.  
  175. typedef struct
  176. {
  177.     UInt32 id;                // ordering 1..n, 0 = no relavent ordering of buttons / triggers
  178. } TriggerConfigurationInfo;
  179.  
  180. /*
  181.  *
  182.  * axis data & configuration information 
  183.  *
  184.  */
  185.  
  186. typedef enum
  187. {
  188.     kAxisCenter = 0,
  189.     kAxisMaximum = 0x7FFFFFFFL,
  190.     kAxisMinimum = 0x80000000L
  191. } AxisData;
  192.  
  193. typedef struct
  194. {
  195.     Boolean    SymetricAxis;    // axis is symetric and can produce both positive and negative data
  196. } AxisConfigurationInfo;
  197.  
  198. // ********************* user level functions *********************
  199.  
  200. /*
  201.  * GetDeviceDefinition
  202.  *
  203.  * pass in the device reference, sizeof(DeviceDefinition) and this will 
  204.  * return the device definition struct for that device into the buffer pointed to 
  205.  * by outStruct
  206.  *
  207.  * Return Codes
  208.  * paramErr
  209.  *
  210.  */
  211.  
  212. OSStatus GetDeviceDefinition(const DeviceReference inDevice, UInt32 buflen, DeviceDefinition *outStruct);
  213.  
  214.  
  215. /*
  216.  *
  217.  * GetDeviceElementList
  218.  *
  219.  * pass in the device reference and this will return the element list for that device
  220.  * you are prohibited from modifiying this element list 
  221.  *
  222.  * Return Codes
  223.  * paramErr
  224.  *
  225.  */
  226.  
  227. OSStatus GetDeviceElementList(const DeviceReference inDevice, ElementListReference *outElementList);
  228.  
  229. /*
  230.  *
  231.  * takes an ElementReference and returns the group that it is in or
  232.  * nil if there is no group
  233.  *
  234.  * Return Codes
  235.  * paramErr if inElement is 0
  236.  *
  237.  */
  238.  
  239. OSStatus GetElementGroup(const ElementReference inElement, UInt32 *outGroup);
  240.  
  241. /*
  242.  *
  243.  * takes an ElementReference and returns the device that the element belongs 
  244.  * to.
  245.  *
  246.  * Return Codes
  247.  * paramErr if inElement is 0or outDevice is nil
  248.  *
  249.  */
  250.  
  251. OSStatus GetElementDevice(const ElementReference inElement, DeviceReference *outDevice);
  252.         
  253. /*
  254.  *
  255.  * takes an ElementReference and gives the ElementInfo for that Element.  This is the
  256.  * the set of standard information.  You get ElementKind specific information
  257.  * through GetElementConfigurationInfo.
  258.  *
  259.  * Return Codes
  260.  * paramErr if inElement is 0 or outInfo is nil
  261.  *
  262.  */
  263.  
  264. OSStatus GetElementInfo(const ElementReference inElement, ElementInfoPtr outInfo);
  265.         
  266. /*
  267.  *
  268.  *         
  269.  *
  270.  * takes an ElementReference and gives the ElementKind specific configuration information
  271.  * 
  272.  * if buflen is not long enough to hold the information GetElementConfigurationInfo will
  273.  * copy buflen bytes of the data into the block of memory pointed to by configInfo and
  274.  * will return something error.
  275.  *
  276.  * Return Codes
  277.  * paramErr if inElement or configInfo is nil
  278.  * something error if buflen is not long enough to hold the information
  279.  *
  280.  */
  281.  
  282. OSStatus GetElementConfigurationInfo(const ElementReference inElement, UInt32 buflen, void *configInfo);
  283.     
  284. /*
  285.  *
  286.  * GetElementSimpleState
  287.  *
  288.  * Takes an ElementReference and returns the current state of that element.  This is a 
  289.  * specialized version of GetElementComplexState that is only appropriate for elements
  290.  * whose data fits in a signed 32 bit integer.
  291.  *
  292.  *
  293.  *
  294.  * Return Codes
  295.  * paramErr if inElement is 0 or state is nil
  296.  * err1 if the elements data does not fit in a signed 32 bit integer
  297.  *
  298.  */
  299.  
  300. OSStatus GetElementSimpleState(const ElementReference inElement, SInt32 *state);
  301.  
  302. /*
  303.  *
  304.  * GetElementComplexState
  305.  *
  306.  * Takes an ElementReference and returns the current state of that element.  
  307.  * Will copy up to buflen bytes of the current state of the device into
  308.  * state.
  309.  *
  310.  *
  311.  * Return Codes
  312.  * paramErr if inElement is 0 or state is nil
  313.  * err2 if buflen is not large enough to hold all the data
  314.  *
  315.  */
  316.  
  317. OSStatus GetElementComplexState(const ElementReference inElement, UInt32 buflen, void *state);
  318.  
  319.  
  320. /*
  321.  * ElementGetNextEvent
  322.  *
  323.  * changed 3/14/96
  324.  *
  325.  * It takes in an element  reference and the buffer size of the ElementEventPtr
  326.  * it will set wasEvent to true if there was an event and false otherwise.  If there
  327.  * was not enough space to fill in the whole event structure that event will be
  328.  * dequed, as much of the event as will fit in the buffer will by copied and
  329.  * ElementGetNextEvent will return an error.
  330.  *
  331.  * Return Codes
  332.  * paramErr
  333.  * somethingErr - buffer to small
  334.  */
  335.  
  336. OSStatus ElementGetNextEvent(ElementReference inElement, UInt32 bufSize, ElementEventPtr event, Boolean *wasEvent);
  337.  
  338. /*
  339.  *
  340.  * ElementFlush
  341.  *
  342.  * It takes an ElementReference and flushes all the events on that element.  All it guaruntees is
  343.  * that any events that made it to this layer before the time of the flush call will be flushed and
  344.  * it will not flush any events that make it to this layer after the time when the call has returned.
  345.  * What happens to events that occur during the flush is undefined.
  346.  *
  347.  *
  348.  * Return Codes
  349.  * paramErr
  350.  *
  351.  */
  352.  
  353. OSStatus ElementFlush(ElementReference inElement);
  354.  
  355.  
  356.  
  357. /*
  358.  * NewElementList
  359.  *
  360.  * Creates a new element list and returns it in outElementList
  361.  *
  362.  *
  363.  * Return Codes
  364.  * out of memory - If it failed to allocate the list because it was out of memory
  365.                    it will also set outElementList to 0
  366.  * paramErr if outElementList was nil
  367.  *
  368.  *
  369.  * Special Concerns
  370.  *
  371.  * interrupt unsafe
  372.  *
  373.  */
  374.  
  375. OSStatus NewElementList(ElementListReference *outElementList);
  376.  
  377. /*
  378.  * DisposeElementList
  379.  *
  380.  * Deletes an already existing memory list.  
  381.  *
  382.  *
  383.  * Return Codes
  384.  * paramErr if inElementList was 0
  385.  *
  386.  *
  387.  * Special Concerns
  388.  *
  389.  * interrupt unsafe
  390.  *
  391.  */
  392.  
  393. OSStatus DisposeElementList(ElementListReference inElementList);
  394.  
  395. /*
  396.  * GetGlobalElementList
  397.  *
  398.  * returns the global element list
  399.  *
  400.  * Return Codes
  401.  * paramErr if outElementList is nil
  402.  *
  403.  */ 
  404.  
  405. OSStatus GetGlobalElementList(ElementListReference *outElementList);
  406.  
  407. /*
  408.  * ElementListAddElement
  409.  *
  410.  * adds an element to the element list
  411.  *
  412.  * Return Codes
  413.  * paramErr if inElementList is 0 or newElement is 0
  414.  * memory error if the system is unable to allocate enough memory
  415.  *
  416.  * Special Concerns
  417.  * interrupt Unsafe
  418.  * 
  419.  */
  420. OSStatus ElementListAddElement(ElementListReference inElementList, UInt32 refCon, ElementReference newElement);
  421.  
  422. /*
  423.  * ElementListRemoveElement
  424.  *
  425.  * removes the specified element from the element list
  426.  *
  427.  * Return Codes
  428.  * paramErr if inElementList is 0 or oldElement is 0
  429.  * memory error if the system is unable to allocate enough memory
  430.  *
  431.  * Special Concerns
  432.  * interrupt Unsafe
  433.  * 
  434.  */
  435.  
  436. OSStatus ElementListRemoveElement(ElementListReference inElementList, ElementReference oldElement);
  437.  
  438. /*
  439.  * ElementListExtract
  440.  *
  441.  * ElementListExtract will extract as many of the elements from an element list as possible.  You pass
  442.  * in an element list, a pointer to an array of element references and the number of elements in that array.
  443.  * It will return how many items are in the element list in the outCount parameter and copy the minimum of 
  444.  * that number and the size of the array into the buffer.
  445.  *
  446.  * ByKind and ByLabel are the same except that they will only count and copy element references to elements
  447.  * that have the specified kind and label.
  448.  *
  449.  * Return Codes
  450.  * paramErr
  451.  *
  452.  */
  453.  
  454. OSStatus ElementListExtract(ElementListReference inElementList, UInt32 inBufferCount, UInt32 *outCount, ElementReference *buffer);
  455. OSStatus ElementListExtractByKind(ElementListReference inElementList, ElementKind theKind, UInt32 inBufferCount, UInt32 *outCount, ElementReference *buffer);
  456. OSStatus ElementListExtractByLabel(ElementListReference inElementList, ElementLabel theLabel, UInt32 inBufferCount, UInt32 *outCount, ElementReference *buffer);
  457.  
  458. /*
  459.  * ElementListGetNextEvent
  460.  *
  461.  * changed 3/14/96
  462.  *
  463.  * It takes in an element list reference and the buffer size of the ElementEventPtr
  464.  * it will set wasEvent to true if there was an event and false otherwise.  If there
  465.  * was not enough space to fill in the whole event structure that event will be
  466.  * dequed, as much of the event as will fit in the buffer will by copied and
  467.  * ElementListGetNextEvent will return an error.
  468.  *
  469.  * Return Codes
  470.  * paramErr
  471.  * somethingErr - buffer to small
  472.  */
  473.  
  474. OSStatus ElementListGetNextEvent(ElementListReference inElementList, UInt32 bufSize, ElementEventPtr event, Boolean *wasEvent);
  475.  
  476. /*
  477.  *
  478.  * ElementListFlush
  479.  *
  480.  * It takes an ElementListReference and flushes all the events on that list.  All it guaruntees is
  481.  * that any events that made it to this layer before the time of the flush call will be flushed and
  482.  * it will not flush any events that make it to this layer after the time when the call has returned.
  483.  * What happens to events that occur during the flush is undefined.
  484.  *
  485.  *
  486.  * Return Codes
  487.  * paramErr
  488.  *
  489.  */
  490.  
  491. OSStatus ElementListFlush(ElementListReference inElementList);
  492.  
  493.  
  494. // ********************* driver level functions *********************
  495.  
  496.  
  497. /*
  498.  *
  499.  * NewDevice
  500.  *
  501.  * This creates a new device from the device definition structure and returns
  502.  * the result into the device reference.
  503.  *
  504.  * Returns Codes
  505.  * paramErr
  506.  * out of memory
  507.  * 
  508.  * Specical Considerations
  509.  * may not be done at interrupt time
  510.  */
  511.  
  512. OSStatus NewDevice(const DeviceDefinition *inStruct, DeviceReference *outReference);
  513.  
  514. /*
  515.  * DisposeDevice
  516.  *
  517.  * This disposes an existing device.
  518.  *
  519.  * Returns Codes
  520.  * paramErr
  521.  *
  522.  * Special Considerations
  523.  * May not be done at interrupt time
  524.  *
  525.  */
  526.  
  527. OSStatus DisposeDevice(DeviceReference *inReference);
  528.  
  529. /*
  530.  *
  531.  * ElementDefinitionStruct
  532.  *
  533.  * This is the structure that defines everything static about this
  534.  * element.  For each element on your device you will need to 
  535.  * fill in one of these structures when your driver loads.
  536.  *
  537.  */
  538.  
  539. typedef struct 
  540. {
  541.     DeviceReference device;  // device this element belongs to
  542.     UInt32 group;             // group this element belongs to or 0
  543.     
  544.     Str63 theString;         // a string that is a human readable identifier for this element, internationalization ?
  545.         
  546.     ElementKind kind;        
  547.     ElementLabel label;        
  548.     
  549.     void *configInfo;         // a pointer to the buffer containing the configuration information for this element
  550.     UInt32 configInfoLength; // length of that configuration info
  551.  
  552.     UInt32 dataSize;         // the size of the data, so we can generate an appropriate buffer
  553. } ElementDefinitionStruct;
  554.  
  555. /*
  556.  *
  557.  * NewElement
  558.  *
  559.  * NewElement takes an element definition struct and gives you back a element reference.
  560.  * When you produce data you use that element reference to give the data to the system.
  561.  * 
  562.  * Return Codes
  563.  * paramErr
  564.  * memory error
  565.  *
  566.  * Special Considerations
  567.  * The NewElement function may move or purge memory.  Your application should not call this function 
  568.  * at interrupt time.
  569.  * 
  570.  */
  571.  
  572. OSStatus NewElement(const ElementDefinitionStruct *inStruct, ElementReference *outElement);
  573.  
  574. /*
  575.  *
  576.  * DisposeElement
  577.  *
  578.  * DisposeElement takes an element reference and deletes it.
  579.  * You should call this function when your driver unloads.
  580.  *
  581.  * Return Codes
  582.  * paramErr
  583.  * memory error
  584.  *
  585.  * Special Considerations
  586.  * The DisposeElement function may move or purge memory.  Your application should not call this function 
  587.  * at interrupt time.
  588.  * 
  589.  */
  590.  
  591. OSStatus DisposeElement(ElementReference inElement);
  592.  
  593. /*
  594.  *
  595.  * ElementPushSimpleData
  596.  *
  597.  * ElementPushSimpleData is the appropriate way to give the system data if your data fits exactly into
  598.  * a 32 bit signed number.  You pass the element reference that goes with the data, the data and the 
  599.  * AbsoluteTime that data was produced.  If UpTime is not available you should fill time.lo with the
  600.  * TickCount time and time.hi with 0.
  601.  *
  602.  * Return Codes
  603.  * paramErr
  604.  *
  605.  */
  606.  
  607. OSStatus ElementPushSimpleData(ElementReference inElement, SInt32 data, const AbsoluteTime *time);
  608.  
  609. /*
  610.  *
  611.  * ElementPushComplexData
  612.  *
  613.  * ElementPushComplexData is exactly like ElementPushSimpleData except that it is appropriate for times
  614.  * when your data does not fit into a signed 32 bit integer.
  615.  *
  616.  * Instead it takes the length of your data (which must match the datasize field of your ElementDefinitionStruct)
  617.  * and a ptr to the devices state.
  618.  *
  619.  * Return Codes
  620.  * paramErr
  621.  *
  622.  */
  623.  
  624. OSStatus ElementPushComplexData(ElementReference inElement, UInt32 buflen, void *state, const AbsoluteTime *time);    
  625.  
  626. #ifdef __cplusplus
  627. }
  628. #endif
  629.  
  630. #endif // __InputSprocket__
  631.